package com.ershijin.authserver.service.security;

import com.ershijin.common.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * 自定义 UserDetailsService
 */
@Service
@RequiredArgsConstructor
public class CustomizerUserDetailsService implements UserDetailsService {
    private final PasswordEncoder passwordEncoder;

    @Override
    public User loadUserByUsername(String username) throws UsernameNotFoundException {

        User user = new User("admin", passwordEncoder.encode("123"), AuthorityUtils.createAuthorityList("USER", "order"));
        user.setId(1001L);
        return user;
    }
}
